﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crosland.Automotriz.Core;
using System.Data.SqlClient;
namespace Crosland.Automotriz.Data.Dao.Linq
{
    public class clsGenerarImportacionDAO
    {
        private readonly AutomotrizEntities ContextoDeObjs = new AutomotrizEntities();


        public bool generar(int ID_ORG_VTA,String ID_GRUPO_ARTICULOS,string fec_ini,string fec_fin,string tipo_abc,string id_usuario) {
                    
                ContextoDeObjs.CommandTimeout = 600;
                ContextoDeObjs.ExecuteStoreCommand(String.Format("exec USP_GENERA_PRONOSTICO {0},'{1}','{2}','{3}','{4}','{5}'", ID_ORG_VTA,ID_GRUPO_ARTICULOS, fec_ini, fec_fin, tipo_abc, id_usuario));
               return true;  
        }



        public IEnumerable<Object> listaCorreoPronostico() {
                IEnumerable<Object>list=new List<Object>();         

                var q = from c in ContextoDeObjs.V_Usuario
                        from d in ContextoDeObjs.T_MAE_TABLA_GENERAL_CAB
                        from g in ContextoDeObjs.T_MAE_TABLA_GENERAL_DET
                        where c.ID_USUARIO==g.DES_CORTA && d.ID_GENERAL_CAB==g.ID_GENERAL_CAB
                        && d.NOM_TABLA == "T_IMP_PRONOSTICO_RPTO_CORREO"
                        select new
                        {
                           g.DES_CORTA,
                           NOMBRE_APELLIDOS = c.DES_NOMBRE+" "+ c.DES_APELLIDOS,
                           c.DES_EMAIL                          

                        };
                list = q.ToList();            
            return list;
        
        }



        public List<T_MAE_TABLA_GENERAL_DET> ListaArticulos() {

            List<T_MAE_TABLA_GENERAL_DET> list = new List<T_MAE_TABLA_GENERAL_DET>();
            try
            {
                var q = from c in ContextoDeObjs.T_MAE_TABLA_GENERAL_CAB
                        from d in ContextoDeObjs.T_MAE_TABLA_GENERAL_DET
                        where c.ID_GENERAL_CAB == d.ID_GENERAL_CAB
                        && c.NOM_TABLA == "T_PRONOSTICO_IMP_PARAMETROS"
                        select d;

                list = q.ToList();

            }
            catch (Exception ex)
            {
                
                throw ex;
            }

            return list;
        
        }



       
           
        
    }
}
